﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;

namespace WindowsFormsApplication1
{
    public partial class frmVatan : Form
    {
       public string[] Params;

        public frmVatan()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //string[] Params= Environment.GetCommandLineArgs();

            //MessageBox.Show(Params[1]);


            SrvInf.AuthHeader SrvInfAuth = new SrvInf.AuthHeader();
            SrvInfAuth.Username = Params[1]; //"test@kalemservis.com";
            SrvInfAuth.Password = Params[2];// "12up73w6";

            SrvInf.v2ServisInformationRequest SrvInfReq = new SrvInf.v2ServisInformationRequest();
            SrvInfReq.AuthHeader = SrvInfAuth;
            SrvInfReq.servisNo = textBox1.Text;

            SrvInf.ServisInformationSoapClient SIS = new SrvInf.ServisInformationSoapClient();//ServisInformationSoapClient("ServisInformationSoap")
            string XmlStr= SIS.v2ServisInformation(SrvInfAuth, textBox1.Text).GetXml();
            //MessageBox.Show(SIS.v2ServisInformation(SrvInfAuth, textBox1.Text).GetXml());

            SqlConnection conn = null;

            try
            {
                conn = new SqlConnection("Data Source=20.10.2.11;Initial Catalog=data29;Persist Security Info=True;User ID=klm;Password=klm2013*");
                conn.Open();
                SqlCommand cmd = new SqlCommand("sp_WebService", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@typ", SqlDbType.Int).Value = 1;
                cmd.Parameters.Add("@irsaliyeno", SqlDbType.VarChar).Value = textBox1.Text;
                cmd.Parameters.Add("@xml", SqlDbType.VarChar).Value = XmlStr;
                cmd.ExecuteNonQuery();

            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }

            Application.Exit();
        }

        private void Form1_Shown(object sender, EventArgs e)
        {
            if (Environment.GetCommandLineArgs().Count() < 3)
                Application.Exit();

            Params = Environment.GetCommandLineArgs();

            textBox1.Text = Params[3];
            if (textBox1.Text=="")
                Application.Exit();
        }
    }
}
